package com.mall.b2c.service.impl;

import com.google.common.collect.Lists;
import com.mall.b2c.bean.IntergralLogBean;
import com.mall.b2c.bean.IntergralShopOrderBean;
import com.mall.b2c.dao.IntergralDao;
import com.mall.b2c.dao.IntergralLogDao;
import com.mall.b2c.dao.MemberDao;
import com.mall.b2c.dao.ShopCartItemDao;
import com.mall.b2c.domain.intergral.IntergralDomain;
import com.mall.b2c.domain.intergral.IntergralLogDomain;
import com.mall.b2c.domain.intergral.ShopCartItemDomain;
import com.mall.b2c.domain.member.MemberDomain;
import com.mall.b2c.service.IntergralLogService;
import com.mall.b2c.service.IntergralService;
import com.mall.common.bean.Order;
import com.mall.common.bean.Pager;
import com.mall.common.exception.NoticeException;
import com.mall.common.hibernate.Finder;
import com.mall.common.service.impl.BaseServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.persistence.LockModeType;
import java.math.BigDecimal;
import java.util.List;

/**
 * Created by chen on 16/12/15.
 */
@Service
@Transactional
public class IntergralLogServiceImpl extends  BaseServiceImpl<IntergralLogDomain, Long> implements IntergralLogService {



    @Resource
    public void setBaseDao(IntergralLogDao intergralLogDao) {
        super.setBaseDao(intergralLogDao);
    }

    public Pager findByUid(Long userId, Integer pageNumber, Integer pageSize){
        Finder finder = Finder.create("from IntergralLogDomain bean where bean.member.id = :id");
        finder.setParam("id", userId);
        finder.setOrder(new Order("createDate", Order.Direction.desc));
        Pager pager = new Pager();
        pager.setPageNumber(pageNumber == null ? 1 : pageNumber);
        pager.setPageSize(pageSize);
        pager = findByPager(pager, finder);
        List list =  pager.getList();
        List<IntergralLogBean> resultList = Lists.newArrayList();
        if(list != null && list.size() > 0)
        {
            for(Object obj : list){
                IntergralLogDomain log = (IntergralLogDomain)obj;
                resultList.add(new IntergralLogBean(log));
            }
            pager.setList(resultList);
        }
        return pager;
    }



}





